 

package com.zdkj.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.admin.api.entity.SwStWebNotic;
import com.zdkj.admin.service.SwStWebNoticService;
import com.zdkj.common.core.util.R;
import com.zdkj.common.data.mybatis.wrapper.CustomQueryWrapper;
import com.zdkj.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 系统通知主表
 *
 * @author zdkj code generator
 * @date 2020-05-12 17:33:55
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swstwebnotic" )
@Api(value = "swstwebnotic", tags = "系统通知主表管理")
public class SwStWebNoticController {

    private final  SwStWebNoticService swStWebNoticService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param swStWebNotic 系统通知主表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwStWebNoticPage(Page page, SwStWebNotic swStWebNotic) {
        return R.ok(swStWebNoticService.page(page, Wrappers.query(swStWebNotic)));
    }

    /**
     * 分页查询关联内容
     * @param page 分页对象
     * @param swStWebNotic 系统通知主表
     * @return
     */
    @ApiOperation(value = "分页查询关联内容", notes = "分页查询关联内容")
    @GetMapping("/pageLink" )
    public R getSwStWebNoticPageLink(Page page, SwStWebNotic swStWebNotic) {
        return R.ok(swStWebNoticService.pageLink(page,new CustomQueryWrapper(SwStWebNotic.class)
                .addDTO(swStWebNotic)
                .init() ));
    }


    /**
     * 通过id查询系统通知主表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(swStWebNoticService.getById(id));
    }

    /**
     * 新增系统通知主表
     * @param swStWebNotic 系统通知主表
     * @return R
     */
    @ApiOperation(value = "新增系统通知主表", notes = "新增系统通知主表")
    @SysLog("新增系统通知主表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin_swstwebnotic_add')" )
    public R save(@RequestBody SwStWebNotic swStWebNotic) {
        return R.ok(swStWebNoticService.save(swStWebNotic));
    }

    /**
     * 修改系统通知主表
     * @param swStWebNotic 系统通知主表
     * @return R
     */
    @ApiOperation(value = "修改系统通知主表", notes = "修改系统通知主表")
    @SysLog("修改系统通知主表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin_swstwebnotic_edit')" )
    public R updateById(@RequestBody SwStWebNotic swStWebNotic) {
        return R.ok(swStWebNoticService.updateById(swStWebNotic));
    }

    /**
     * 修改系统通知已读
     * @param swStWebNotic 系统通知主表
     * @return R
     */
    @ApiOperation(value = "修改系统通知主表已读", notes = "修改系统通知主表已读")
    @SysLog("修改系统通知已读" )
    @PutMapping("/ids")
    @PreAuthorize("@pms.hasPermission('admin_swstwebnotic_edits')" )
    public R updateByIds(@RequestBody List<SwStWebNotic> swStWebNotic) {
       // swStWebNotic.stream().filter(swStWebNotic1 -> swStWebNotic1.getIsRead().equals("1")).collect(Collectors.toList());
        return R.ok(swStWebNoticService.updateBatchById(swStWebNotic));
    }

    /**
     * 通过id删除系统通知主表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除系统通知主表", notes = "通过id删除系统通知主表")
    @SysLog("通过id删除系统通知主表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('admin_swstwebnotic_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(swStWebNoticService.removeById(id));
    }

    /**
     * 通过ids删除系统通知主表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过ids删除系统通知主表", notes = "通过id删除系统通知主表")
    @SysLog("通过ids删除系统通知主表" )
    @DeleteMapping("/ids" )
    @PreAuthorize("@pms.hasPermission('admin_swstwebnotic_dels')" )
    public R removeByIds(@RequestBody List<String>  id) {
        return R.ok(swStWebNoticService.removeByIds(id));
    }

}
